﻿using System;
using System.Drawing.Printing;
using System.Windows;
using System.Windows.Forms;

namespace DocMreoLiteVersion
{
    /// <summary>
    /// Interaction logic for ReportViewverWindow.xaml
    /// </summary>
    public partial class ReportViewverWindow : Window
    {
        private bool _isReportViewerLoaded = false;


        private Object transfer_object;        
        private String PathReportResource;
        private String NameDataSet;
        
        private System.Windows.Forms.BindingSource m_BindingSource;
        private System.ComponentModel.IContainer mform_components = null;


        public ReportViewverWindow()
        {
            InitializeComponent();
            m_ReportViewver.Load += m_ReportViewver_Load;

           

            //m_ReportViewver.SetPageSettings();
        }

        public ReportViewverWindow(String PathReportResource, String NameDataSet, Object transfer_object) :
            this()
        {
            this.transfer_object = transfer_object;
            this.PathReportResource = PathReportResource;
            this.NameDataSet = NameDataSet;
       }

        void m_ReportViewver_Load(object sender, EventArgs e)
        {
            if (!_isReportViewerLoaded)
            {
                this.mform_components = new System.ComponentModel.Container();
                this.m_BindingSource = new System.Windows.Forms.BindingSource(this.mform_components);                                
                this.m_ReportViewver.LocalReport.ReportEmbeddedResource = PathReportResource;


                ((System.ComponentModel.ISupportInitialize)(this.m_BindingSource)).BeginInit();
                this.m_ReportViewver.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource(this.NameDataSet, m_BindingSource));

                ((System.ComponentModel.ISupportInitialize)(this.m_BindingSource)).EndInit();

                _isReportViewerLoaded = true;
            }


            this.m_BindingSource.DataSource = transfer_object;

            m_ReportViewver.RefreshReport();


        }

        private void m_ReportViewver_Print_1(object sender, Microsoft.Reporting.WinForms.ReportPrintEventArgs e)
        {
            //System.Windows.MessageBox.Show("Печвть бланка...");           
        }

    }
}
